public class Main {
    public static int solution(int n) {
        if (n <= 1) {
            return 0;
        }
        int matches;
        if (n % 2 == 0) {
            matches = n / 2;
            n = matches;
        } else {
            matches = (n - 1) / 2;
            n = matches + 1;
        }
        return matches + solution(n);
    }

    public static void main(String[] args) {
        System.out.println(solution(7) == 6);   // true
        System.out.println(solution(14) == 13); // true
        System.out.println(solution(1) == 0);   // true
    }
}